package com.hzzh.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hzzh.dao.EmployeeDAO;
import com.hzzh.service.MeetingRoomService;
import com.hzzh.service.MeetingService;
import com.hzzh.vo.Meeting;

/**
 * Servlet implementation class ViewMyMeetingsServlet
 */
@WebServlet("/ViewMyMeetingsServlet")
public class ViewMyMeetingsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewMyMeetingsServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//我的会议
		//获取session中的employeeid
		HttpSession session=request.getSession();
		int employeeid=(Integer) session.getAttribute("employeeid");
		
		MeetingService service=new MeetingService();
		MeetingRoomService roomService=new MeetingRoomService();
		EmployeeDAO empDao=new EmployeeDAO();
		//通过employeeid查询某员工参加的所有会议
		List<Meeting> meetingsList=service.viewMymeetingsInfo(employeeid);
		List<String[]>  nameList=new ArrayList<String[]>();
		
		
		for(Meeting m:meetingsList){
			//将员工姓名和会议室名存到一个集合里
			String empName=empDao.selectById(m.getReservationistid()).getEmployeename();
			String roomName=roomService.viewOneMeetingRoom(m.getRoomid()).getRoomname();
			nameList.add(new String[]{empName,roomName});
		}
		
		Map<Meeting,String[]> map=new HashMap<Meeting,String[]>();
		
		for(int i=0;i<meetingsList.size();i++){
			map.put(meetingsList.get(i), nameList.get(i));
		}
		
		request.setAttribute("map", map);
		
		request.getRequestDispatcher("mymeetings.jsp").forward(request, response);
		
		
		
	}

}
